package cn.itcast.dmp.report

import cn.itcast.dmp.config.AppConfigHelper
import cn.itcast.dmp.process.ReportProcessor
import org.apache.avro.generic.GenericData
import org.apache.spark.sql.DataFrame
import org.apache.spark.sql.types.StringType

object ReportRegionProcessor extends ReportProcessor{
  override def targetTableName: String ={
    AppConfigHelper.REPORT_REGION_STAT_TABLE_NAME}


  override def targetTableKeys: Seq[String] = {
    Seq("report_date","province","city")

  }
//  每个报表子类必须实现的方法，真正的依据报表需求进行分析数据
  override def realProcessData(odsDF: DataFrame): DataFrame = {
    import odsDF.sparkSession.implicits._
    import org.apache.spark.sql.functions._
    // 按照省份、城市分组，进行统计count
    val reportDF = odsDF.groupBy($"province", $"city").count()
      .select(
        current_date().cast(StringType).as("report_date"), $"province", $"city", $"count"
      )
//返回dataframe  // 返回报表
    reportDF
  }
}
